<script setup>
import { ref, reactive, onMounted } from "vue";
import { ConnectToSSE,StopSSE } from "../../wailsjs/go/api/CustomerApi.js";
const message = ref("");
const startSSE = async () => {
  await ConnectToSSE();
  window.runtime.EventsOn("sse_event", (data) => {
    console.log("收到SSE事件:", data);
    // 解析标准SSE格式
    // const event = parseSSEEvent(data);
    // if (event.type === "update") {
    //   updateUI(event.data);
    // }
  });
}
const stopSSE = async () => {
  const res = await StopSSE()
  console.log("stopSSE",res)
}
</script>

<template>
  <div>
    <h1>SSE 事件监听</h1>
    <div class="h-96 bg-gray-200 border-2 border-gray-400">
    </div>
    <div class="flex justify-center">
      <button @click="startSSE" class="mr-4 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">startSSE</button>
      <button @click="stopSSE" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">stopSSE</button>
    </div>
  </div>
</template>

<style scoped lang="scss">
</style>